﻿/**
 * Proyecto: Cognitum
 * Global IT Services 2008
 * @author Esanantonio
 */

Cognitum.Mensajeria.Ruta.Editor = Ext.extend(Karma.EBCard, {

	initComponent: function(){
		Ext.apply(this, {
			sections: [{
		        title: 'Ruta',
		        items: [{
	                fieldLabel: 'Descripcion',
	                name: 'Descripcion'
	            },
	            {
	                fieldLabel: 'Fecha',
	                name: 'FechaRuta',
	                xtype: 'datefield'
	            },
	            {
	                fieldLabel: 'Mensajero',
	                name: 'Mensajero',
	                entityName: 'Usuario',
	                xtype: 'entity.link'
	            },
	            {
                    fieldLabel: 'Estatus',
                    name: 'Estatus',
                    xtype: 'enum.combo',
                    enumName: 'Cognitum.Dominio.Aplicacion.EstatusEnum',
                    hidden:true,
                    hideLabel:true
                }]
	        }, {
	            title: 'Solicitudes',
	            items: [
	            {
                    hideLabel: true,
                    name: 'Solicitudes',
                    entityName: 'SolicitudMensajeria',                    
                    xtype: 'entity.list',                
				    selectionConfig: {
					    multiSelect: true,
					    width: 700
				    },
				    context: 's.Ruta.Id=? ',
				    /*selectContextQuery: 'r.Id in (select r1.Id from Recibo where r1.Tramite.Id = 22187)',*/
                    anchor: '100% 100%',
				    /*listeners: {
					    'beforeadd': {
						    fn: this.actualizaTotales,
						    scope: this
					    },
					    'beforedelete': {
						    fn: this.actualizaTotales,
						    scope: this
					    }
				    },
                    updateControls: function(ruta){
                        if (Ext.isEmpty(liquidacion)) {
                            return;
                        }
                        // menu config
                        this.deleteMenuAction.setDisabled(!(this.canDelete && ruta.Estatus == 0));
                        this.newToolbarButton.setDisabled(!(this.canNew && ruta.Estatus == 0));
                    },*/
                    onBeforeAdd: function(ids, data, liquidacion){
                        if (Ext.isEmpty(liquidacion)) {
                            return;
                        }
					    Ext.MessageBox.show({
					       msg: 'Procesando...',
					       progressText: 'Saving...',
					       width: 300,
					       wait: true,
					       waitConfig: { interval: 200 }
					    });
                        this.entity.useInvoker('DoAsignaRuta', [ids, liquidacion.Id], {
                            fn: function(){
                                this.reload();
							    this.fireEvent('beforeadd');
							    Ext.MessageBox.hide();
                            },
                            scope: this
                        });
                    },
                    onBeforeDelete: function(id){
                        if (Ext.isEmpty(id)) {
                            return;
                        }
					    Ext.MessageBox.show({
					       msg: 'Procesando...',
					       progressText: 'Saving...',
					       width: 300,
					       wait: true,
					       waitConfig: { interval: 200 }
					    });
                        this.entity.useInvoker('DoDesasignaRuta', id, {
                            fn: function(){
                                this.reload();
							    this.fireEvent('beforedelete');
							    Ext.MessageBox.hide();
                            },
                            scope: this
                        });
                    }
                }/*
	                {
	                hideLabel: true,
	                name: 'Solicitudes',
	                entityName: 'SolicitudMensajeria',
	                xtype: 'ag.list',
	                context: 's.Ruta = ?',
	                anchor: '99% 99%'
                    }*/
                    ]
	        }, {
                xtype: 'sec.editor',
                title: 'Seguridad'
            }, {
                xtype: 'aud.editor',
                title: 'Auditoria'
}]
		});
		Cognitum.Mensajeria.Ruta.Editor.superclass.initComponent.apply(
			this, arguments);
	}	
});

Ext.reg('rut.editor', Cognitum.Mensajeria.Ruta.Editor);
